var CompanyView = function() {
    return this.setup();
};
CompanyView.prototype.setup = function() {
    var b = this.topbar();
    var a = new Ext.form.FormPanel({
        id : "CompanyView",
        closable : true,
        url : __ctxPath + "/system/saveCompanyInfo.do",
        title : "公司信息",
        layout : "form",
        tbar : b,
        autoScroll : true,
        iconCls : "menu-company",
        items : [ {
            xtype : "hidden",
            name : "companyInfo.id",
            id : "companyInfoid"
        }, {
            xtype : "container",
            labelAlign : "top",
            border : false,
            width : 500,
            style : "padding-left:10%;padding-right:10%",
            layout : "form",
            items : [ { 
                layout : "column",
                border : false,
                anchor : "78%",
                items :[{
                    layout : "form",
                    columnWidth : 0.5,
                    border : false,
                    style : "padding-left:0px;",
                    items : [{
                        xtype : "textfield",
                        fieldLabel : "公司编号",
                        name : "companyInfo.companyNo",
                        id : "companyInfocompanyNo",
                        anchor : "98%"
                    }]
                },{
                    layout : "form",
                    columnWidth : 0.5,
                    border : false,
                    style : "padding-left:0px;",
                    items : [{
                        xtype : "textfield",
                        fieldLabel : "公司名称",
                        name : "companyInfo.companyName",
                        id : "companyInfocompanyName",
                        allowBlank : false,
                        anchor : "98%"
                    }]
                }]

            }, {
                layout : "column",
                border : false,
                anchor : "78%",
                items : [ {
                    layout : "form",
                    columnWidth : 0.5,
                    border : false,
                    style : "padding-left:0px;",
                    items : [ {
                        xtype : "textfield",
                        fieldLabel : "法人代表",
                        name : "companyInfo.legalPerson",
                        id : "companyInfolegalPerson",
                        anchor : "98%"
                    }, {
                        xtype : "textfield",
                        fieldLabel : "公司固话",
                        name : "companyInfo.phone",
                        id : "companyInfophone",
                        anchor : "98%"
                    },{
                        xtype : "textfield",
                        fieldLabel : "邮编",
                        name : "companyInfo.postalcode",
                        id : "companyInfopostalcode",
                        anchor : "98%"
                    } ]
                }, {
                    layout : "form",
                    border : false,
                    columnWidth : 0.5,
                    items : [ {
                        fieldLabel : "成立时间",
                        xtype : "datefield",
                        format : "Y-m-d",
                        name : "companyInfo.setupDate",
                        id : "companyInfosetupDate",
                        value : new Date(),
                        anchor : "98%"
                    }, {
                        xtype : "textfield",
                        fieldLabel : "传真",
                        name : "companyInfo.fax",
                        id : "companyInfofax",
                        anchor : "98%"
                    },{
                        xtype : "textfield",
                        fieldLabel : "地址",
                        name : "companyInfo.address",
                        id : "companyInfoaddress",
                        anchor : "98%"
                    } ]
                } ]
            }, {
                xtype : "hidden",
                fieldLabel : "LogoPath",
                name : "companyInfo.LogoPath",
                id : "companyLogoPath"
            }, {
                xtype : "container",
                fieldLabel : "公司主页",
                style : "padding-left:0px;padding-bottom:3px;",
                layout : "column",
                items : [ {
                    xtype : "textfield",
                    name : "companyInfo.site",
                    id : "companyInfosite",
                    width : 300
                }, {
                    xtype : "button",
                    text : "访问公司主页",
                    handler : function() {
                        var e = Ext.getCmp("companyInfosite");
                        var d = e.getValue().trim();
                        if (d.indexOf("http://") == 0) {
                            window.open(d, "_bank");
                        } else {
                            Ext.ux.Toast.msg("提示信息", "没写完整网址.");
                        }
                    }
                }, {
                    xtype : "label",
                    width : 100,
                    text : "以http://开头"
                } ]
            },/* {
                xtype : "container",
                fieldLabel : "Logo",
                style : "padding-left:0px;padding-bottom:3px;",
                layout : "column",
                items : [ {
                    xtype : "container",
                    border : true,
                    style : "padding-left:0px;",
                    layout : "form",
                    height : 58,
                    items : [ {
                        xtype : "panel",
                        height : 55,
                        width : 247,
                        id : "LogoPanel",
                        autoScroll : true,
                        html : '<img src="' + __ctxPath + '/resources/images/default_image_car.jpg" width="100%" height="100%"/>'
                    } ]
                }, {
                    border : false,
                    xtype : "container",
                    layout : "form",
                    width : 93,
                    style : "padding-left:3px;",
                    items : [ {
                        xtype : "button",
                        iconCls : "btn-add",
                        text : "上传LOGO",
                        handler : function() {
                            var d = Ext.getCmp("companyLogoPath");
                            var e = App.createUploadDialog({
                                file_cat : "system/company",
                                callback : c,
                                permitted_extensions : [ "jpg", "png" ]
                            });
                            if (d.getValue() != "" && d.getValue() != null && d.getValue() != "undefined") {
                                var f = "再次上传需要先删除原有图片,";
                                Ext.Msg.confirm("信息确认", f + "是否删除？", function(g) {
                                    if (g == "yes") {
                                        Ext.Ajax.request({
                                            url : __ctxPath + "/system/deleteFileAttach.do",
                                            method : "post",
                                            params : {
                                                filePath : d.value
                                            },
                                            success : function() {
                                                d.setValue("");
                                                var i = Ext.getCmp("LogoPanel");
                                                i.body.update('<img src="' + __ctxPath + '/resources/images/default_image_car.jpg" width="100%" height="100%" />');
                                                var h = document.getElementById("companyLogoPath");
                                                h.src = __ctxPath + "/resources/images/ht-logo.png";
                                                Ext.Ajax.request({
                                                    url : __ctxPath + "/system/delphotoCompany.do",
                                                    method : "post",
                                                    success : function() {
                                                        e.show("queryBtn");
                                                    }
                                                });
                                            }
                                        });
                                    }
                                });
                            } else {
                                e.show("queryBtn");
                            }
                        }
                    }, {
                        xtype : "button",
                        text : "删除LOGO",
                        iconCls : "btn-delete",
                        handler : function() {
                            var d = Ext.getCmp("companyLogoPath");
                            if (d.value != null && d.value != "" && d.value != "undefined") {
                                var e = "LOGO一旦删除将不可恢复,";
                                Ext.Msg.confirm("确认信息", e + "是否删除?", function(f) {
                                    if (f == "yes") {
                                        Ext.Ajax.request({
                                            url : __ctxPath + "/system/deleteFileAttach.do",
                                            method : "post",
                                            params : {
                                                filePath : d.value
                                            },
                                            success : function() {
                                                Ext.Ajax.request({
                                                    url : __ctxPath + "/system/delphotoCompany.do",
                                                    method : "post",
                                                    success : function() {
                                                        d.setValue("");
                                                        var h = Ext.getCmp("LogoPanel");
                                                        h.body.update('<img src="' + __ctxPath + '/resources/images/default_image_car.jpg" width="100%" height="100%" />');
                                                        var g = document.getElementById("companyLogoPath");
                                                        g.src = __ctxPath + "/resources/images/ht-logo.png";
                                                    }
                                                });
                                            }
                                        });
                                    }
                                });
                            } else {
                                Ext.ux.Toast.msg("提示信息", "您还未增加照片.");
                            }
                        }
                    } ]
                }, {
                    border : false,
                    xtype : "label",
                    width : 150,
                    html : '<a style="color:red;">请上传比例为247*55的图片,透明底的图片更佳</a>'
                } ]
            },*/ {
                xtype : "htmleditor",
                fieldLabel : "公司简介",
                name : "companyInfo.companyDesc",
                id : "companyInfocompanyDesc",
                height : 200,
                anchor : "78%"
            } ]
        } ]
    });
    a.loadData({
        url : __ctxPath + "/system/getCompanyInfo.do",
        preName : "companyInfo",
        root : "result",
        success : function(form, action) {
            var g = Ext.util.JSON.decode(form.responseText).data;
            if (g.setupDate) {
                Ext.getCmp("companyInfosetupDate").setValue(new Date(Date.parse(g.setupDate.replace(/-/g, "/"))));
            }
        },
        failure : function(g, h) {
            Ext.ux.Toast.msg("操作提示", "数据加载失败");
        }

    });
    //	a.form.load({
    //	url : __ctxPath + "/system/getCompanyInfo.do",
    //	deferredRender : false,
    //	waitMsg : "正在载入数据...",
    //	success : function(g, h) {
    //	var j = h.result.data.logoPath;
    //	var i = Ext.getCmp("LogoPanel");
    //						if (j != null && j != "" && j != "undefind"
    //								&& i.body != null) {
    //							i.body.update('<img src="' + __ctxPath
    //									+ "/attachFiles/" + j
    //									+ '"  width="100%" height="100%"/>');
    //						}
    //	},
    //	failure : function(g, h) {
    //		Ext.ux.Toast.msg("操作提示", "数据加载失败");
    //		}
    //				});
    function c(f) {
        var d = Ext.getCmp("companyLogoPath");
        var g = Ext.getCmp("LogoPanel");
        d.setValue(f[0].filePath);
        g.body.update('<img src="' + __ctxPath + "/attachFiles/" + f[0].filePath + '"  width="100%" height="100%"/>');
        var e = document.getElementById("companyLogoPath");
        e.src = __ctxPath + "/attachFiles/" + f[0].filePath;
    }
    return a;
};
CompanyView.prototype.topbar = function() {
    var a = new Ext.Toolbar({
        id : "CompanyTopBar",
        height : 30,
        bodyStyle : "text-align:left",
        items : []
    });
    if (isGranted("_CompanyEdit")) {
        a.add(new Ext.Button({
            text : "保存",
            iconCls : "btn-save",
            handler : function() {
                var b = Ext.getCmp("CompanyView");
                if (b.getForm().isValid()) {
                    b.getForm().submit({
                        waitMsg : "正在修改公司信息",
                        success : function(c, e) {
                            Ext.ux.Toast.msg("操作提示", "公司信息保存成功！");
                            var d = Ext.getCmp("companyinfocompanyName").getValue();
                            Ext.getCmp("toolbarCompanyName").setText(d + "安全生产管理系统");
                        }
                    });
                }
            }
        }));
    }
    a.add(new Ext.Button({
        text : "关闭",
        iconCls : "btn-close",
        handler : function() {
            var b = Ext.getCmp("centerTabPanel");
            b.remove("CompanyView");
        }
    }));
    return a;
};